package com.jeesite.modules.front.web;

import com.jeesite.common.entity.Page;
import com.jeesite.modules.site.entity.SiteArticle;
import com.jeesite.modules.site.entity.SiteFriendlink;
import com.jeesite.modules.site.service.SiteFriendlinkService;
import com.jeesite.modules.site.service.SiteArticleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import com.jeesite.modules.HttpRequestDeviceUtils;

/**
 * Created by chensk on 2018/5/3.
 */

@Controller
@RequestMapping(value = "${frontPath}/index")
public class IndexController {
    @Autowired
    private SiteFriendlinkService siteFriendlinkService;
    @Autowired
    private SiteArticleService siteArticleService;

    /**
     * 查询列表
     */
    @RequestMapping(value = {"list",""})
    public String list( Model model, HttpServletRequest request) {
        SiteFriendlink siteFriendlink = new SiteFriendlink();
        siteFriendlink.setPos(1);
        Page<SiteFriendlink> page = siteFriendlinkService.findPage(new Page<SiteFriendlink>(),siteFriendlink);
        model.addAttribute("scroll",page.getList());

        siteFriendlink.setPos(4);
        Page<SiteFriendlink> page4 = siteFriendlinkService.findPage(new Page<SiteFriendlink>(),siteFriendlink);
        model.addAttribute("corp",page4.getList());

        siteFriendlink.setPos(2);
        Page<SiteFriendlink> page5 = siteFriendlinkService.findPage(new Page<SiteFriendlink>(),siteFriendlink);
        model.addAttribute("banner",page5.getList());

        SiteArticle siteArticle = new SiteArticle();
        siteArticle.setCategory(1);
        Page<SiteArticle> page2 = siteArticleService.findPage(new Page<SiteArticle>(),siteArticle);
        model.addAttribute("article",page2.getList());

        siteArticle.setFlag(1);
        Page<SiteArticle> page3 = siteArticleService.findPage(new Page<SiteArticle>(),siteArticle);
        model.addAttribute("slidearticle",page3.getList());
        if(HttpRequestDeviceUtils.isMobileDevice(request)){

            return "modules/front/wapindex";
        }
        else {
            return "modules/front/index";
        }

    }

}
